package com.jiaai.cloud.user.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.user.entity.TUserSearch;
import com.jiaai.cloud.user.service.ITUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-01
 */
@RestController
@RequestMapping("/api/manage/tUser")
public class TUserController {
    @Autowired
    private ITUserService itUserService;


    @RequestMapping(value = "/findByAll", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findByAll(TUserSearch search) throws ServiceException {
        try {

            EntityWrapper wrapper=new EntityWrapper();
            if(!StringUtils.isEmpty(search.getUserNo())){
                wrapper.like("userNo",search.getUserNo());

            }
            if(!StringUtils.isEmpty(search.getNickName())){
                wrapper.like("nickName",search.getNickName());

            }

            return RestResultGenerator.genSuccessResult(itUserService.findByall(search.getPagePlus(),wrapper));
        } catch (Exception e) {
            throw new ServiceException("查询失敗", e.getMessage());
        }
    }
    //删
    @RequestMapping(value ="/deleteId/{userId}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("userId") String userId) throws ServiceException {
        try {
            itUserService.deleteById(userId);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }

    @RequestMapping(value = "/selectUser" ,method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object selectUser() throws ServiceException {
        try {
            return RestResultGenerator.genSuccessResult(itUserService.selectUser());
        } catch (Exception e) {
            throw new ServiceException("统计失敗");
        }
    }


    @RequestMapping(value = "/allUser" ,method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object allUser() throws ServiceException {
        try {
            return RestResultGenerator.genSuccessResult(itUserService.allUser());
        } catch (Exception e) {
            throw new ServiceException("统计失敗");
        }
    }


    @RequestMapping(value = "/selectMonthUser" ,method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object selectMonthUser() throws ServiceException {
        try {
            return RestResultGenerator.genSuccessResult(itUserService.selectMonthUser());
        } catch (Exception e) {
            throw new ServiceException("统计失敗");
        }
    }

	
}
